#pragma once
#include <vector>
#include <string>
#include <set>

namespace sudoku
{
	class Cell
	{
	public:
		int Value;
		std::set<int> Candidates;

		Cell();
		~Cell();

		void clear();
		std::string toJson();
	};

	class Board
	{
	public:
		Board();
		~Board();

		void clear();
		bool loadFromFile(const std::wstring &file);
		bool calculate();
		void showResult();
		std::string showResultAsJson() const;

	private:
		Cell _cell[81];

		inline bool toXY(const int c, int& x, int& y);
		inline bool toPalace(const int x, const int y, int &px, int &py);
		bool calculate(const int c);
		bool getRow(const int x, std::vector<Cell *> &row);
		bool getColumn(const int y, std::vector<Cell *> &col);
		bool getPalace(const int px, const int py, std::vector<Cell *>& pal);
		void getCandidatesFromLine(const int x, std::set<int>& cand);
		void getCandidatesFromColumn(const int y, std::set<int>& cand);
		void getCandidatesFromPalace(const int x, const int y, std::set<int>& cand);
	};
}